package org.my.back;

import java.util.Arrays;
import java.util.Random;

public class Solution {
    public static void main(String[] args) {
        Solution[] arr1 = new Solution[10];
        Solution[] arr2 = new Solution[10000000];
        Arrays.fill(arr1, new Solution());
        Arrays.fill(arr2, new Solution());

        int[] index1 = new int[10000000];
        int[] index2 = new int[10000000];
        for (int i = 0; i < 10000000; i++) {
            index1[i] = new Random().nextInt(10);
            index2[i] = new Random().nextInt(10000000);
        }

        int s1 = 0;
        int s2 = 0;

        long t1 = System.currentTimeMillis();
        for (int i = 0; i < index1.length; i++) {
            s1 += arr1[index1[i]].hashCode();
        }
        long t2 = System.currentTimeMillis();
        System.out.println("访问小数组耗时：" + (t2 - t1));

        long t3 = System.currentTimeMillis();
        for (int i = 0; i < index2.length; i++) {
            s2 += arr2[index2[i]].hashCode();
        }
        long t4 = System.currentTimeMillis();
        System.out.println("访问大数组耗时：" + (t4 - t3));
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s2  );

    }

}
